package com.huang.app.antstore.common.pay.wxpay;

import android.content.Context;
import android.os.AsyncTask;

import com.tencent.mm.sdk.modelpay.PayReq;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import java.util.Map;

/**
 * 必传6个参数.1234参数不为空,1:appid,2:商户id;3:api_key;4:是否已经生成预支付订单,"00",否,"01",已生成预支付订单;5:预支付订单好;6:通知url
 * Created by Administrator on 2015/12/2.
 */
public class WXpayAsyncTask extends AsyncTask<String, Void, Map<String, String>> {
    private static final String TAG = WXpayAsyncTask.class.getName();
    private IWXAPI api;
    Context context;
    String appid, noncestr, partnerid, prepayid, timestamp, sign;

    public WXpayAsyncTask(Context context, String appid, String noncestr, String partnerid, String prepayid, String timestamp, String sign) {
        this.api = WXAPIFactory.createWXAPI(context, appid);
        api.registerApp(appid);
        this.context = context;
        this.appid = appid;
        this.noncestr = noncestr;
        this.partnerid = partnerid;
        this.prepayid = prepayid;
        this.timestamp = timestamp;
        this.sign = sign;
    }

    @Override
    protected Map<String, String> doInBackground(String... params) {
        PayReq req = new PayReq();
        req.appId = appid;
        req.partnerId = partnerid;
        req.prepayId = prepayid;
        req.nonceStr = noncestr;
        req.timeStamp = timestamp;
        req.packageValue = "Sign=WXPay";
        req.sign = sign;
        req.extData = "app data"; // optional
        // 在支付之前，如果应用没有注册到微信，应该先调用IWXMsg.registerApp将应用注册到微信
        api.sendReq(req);
        return null;
    }


}
